<template>
  <el-row class="home" :gutter="20">
    <el-col :span="8">
      <el-card shadow="hover" style="margin-bottom: 10px; padding: 10px; width: 90%">
        <div class="user">
          <img :src="userimg" />
          <div class="user-info">
            <p class="name">长歌</p>
            <p class="access">超级管理员</p>
          </div>
        </div>
        <div class="login-info">
          <p>上次登陆时间: <span>2021-5-20</span></p>
          <p>上次登陆地点: <span>卡莎的心房</span></p>
        </div>
      </el-card>
      <el-card shadow="hover" style="height: 522px; width: 94%">
        <el-table :data="tableData">
          <el-table-column show-overflow-tooltip v-for="(value, key) in tableLabel" :key="key" :prop="key" :label="value"> </el-table-column>
        </el-table>
      </el-card>
    </el-col>
    <el-col :span="16">
      <div class="num">
        <el-card shadow="hover" v-for="item in countData" :key="item.name">
          <i class="icon" :class="`el-icon-${item.icon}`" :style="{ background: item.color }"></i>
          <div class="detail">
            <p class="num">{{ item.value }}</p>
            <p class="txt">{{ item.name }}</p>
          </div>
        </el-card>
      </div>
      <el-card shadow="hover">
        <echart style="height: 280px" :chartData="echartData.order"></echart>
      </el-card>
      <div class="graph">
        <el-card shadow="hover">
          <echart style="height: 260px" :chartData="echartData.user">柱状图</echart>
        </el-card>
        <el-card shadow="hover">
          <echart style="height: 260px" :chartData="echartData.video" :isAxisChart="false">饼图</echart>
        </el-card>
      </div>
    </el-col>
  </el-row>
</template>

<script>
import Echart from '../../components/Echarts.vue'
export default {
  components: {
    Echart,
  },
  data() {
    return {
      userimg: require('../../assets/image/touxiang.jpg'),
      countData: [
        {
          name: '今日心动订单',
          value: '131,4520',
          icon: 's-opportunity',
          color: '#f56c6c',
        },
        {
          name: '今日收藏订单',
          value: '131,4520',
          icon: 'star-on',
          color: '#ffe980',
        },
        {
          name: '今日播放数量',
          value: '17,5890',
          icon: 'video-play',
          color: '#BA55D3',
        },
        {
          name: '今日支付订单',
          value: '131,4520',
          icon: 'success',
          color: '#2ec7c9',
        },
        {
          name: '今日未支付订单',
          value: '1,4520',
          icon: 's-goods',
          color: '#5ab1ef',
        },
        {
          name: '今日CP成功数',
          value: '78,1736',
          icon: 'star-on',
          color: '#3CB371',
        },
      ],
      tableData: [],
      tableLabel: {
        name: '喜欢类型',
        todayBuy: '今日喜欢',
        monthBuy: '本月喜欢',
        totalBuy: '总计喜欢',
      },
      echartData: {
        order: {
          xData: [],
          series: [],
        },
        user: {
          xData: [],
          series: [],
        },
        video: {
          series: [],
        },
      },
    }
  },
  created() {
    this.$nextTick(function () {
      this.getTableData()
    })
  },
  mounted() {},
  methods: {
    getTableData() {
      this.$http.get('/home/getData').then((res) => {
        this.tableData = res.data.data.tableData
        //订单折现图
        var order = res.data.data.orderData
        this.echartData.order.xData = order.date
        //1.取出series中的name部分---键名
        var keyArray = Object.keys(order.data[0])
        keyArray.forEach((key) => {
          this.echartData.order.series.push({
            name: key,
            data: order.data.map((item) => item[key]),
            type: 'line',
          })
        })
        var bar = res.data.data.userData
        this.echartData.user.xData = bar.map((item) => item.date)
        this.echartData.user.series.push({
          name: '新增用户',
          data: bar.map((item) => item.active),
          type: 'bar',
        })
        var pie = res.data.data.videoData
        this.echartData.video.series.push({
          data: pie,
          type: 'pie',
          radius: '50%',
          isAxisChart: false,
        })
      })
    },
  },
}
</script>

<style lang="scss" scoped>
@import '@/assets/scss/home.scss';
</style>
